﻿<%@ Page validateRequest="false" Language="C#" AutoEventWireup="true" CodeBehind="question_edited.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Certificate.question_edited" %>

<%@ Import Namespace="DataAccess" %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <%
        int id = int.Parse(Request.Form["id"]);
        int thutu = int.Parse(Request.Form["thutu"]);
        string name = Request.Form["name"];
        string pa1 = Request.Form["pa1"];
        string pa2 = Request.Form["pa2"];
        string pa3 = Request.Form["pa3"];
        string pa4 = Request.Form["pa4"];
        int type = int.Parse(Request.Form["type"]);

        int pa1_id = int.Parse(Request.Form["pa1_id"]);
        int pa2_id = int.Parse(Request.Form["pa2_id"]);
        int pa3_id = int.Parse(Request.Form["pa3_id"]);
        int pa4_id = int.Parse(Request.Form["pa4_id"]);
        string file = Request.Form["file"];
        int confirm = int.Parse(Request.Form["confirm"]);
        
        new TblQuestionController().Update(pa1_id,id,pa1);
        new TblQuestionController().Update(pa2_id,id,pa2);
        new TblQuestionController().Update(pa3_id,id,pa3);
        new TblQuestionController().Update(pa4_id,id,pa4);

        string[] split = new string[name.Split(' ').Length];
        string edited = "";
        split = name.Split(' ');
        for (int i = 0; i <= name.Split(' ').Length - 1; i++)
        {
            if (split[i] == "/xd/")
                edited += "</br>";
            else
                edited += split[i];
            if (i < name.Split(' ').Length - 1)
                edited += " ";
        }
        
        var get_td_old = new TblTestDetailController().FetchAll().Where(x=>x.TestDetailId==id).Single();
        if (file == "")
            new TblTestDetailController().Update(id, get_td_old.TestId, edited,type, get_td_old.TestDetailUrl, confirm, get_td_old.TestDetailTeacher, get_td_old.TestDetailActive, get_td_old.TestDetailNote);
        else
        {
            string[] temp = new string[file.Split('\\').Length];
            temp = file.Split('\\');
            string temp2 = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + Session["admin_id"].ToString();
            string upload = temp[file.Split('\\').Length - 1];
            upload = temp2 + upload;
            new TblTestDetailController().Update(id, get_td_old.TestId, edited,type, upload, confirm, get_td_old.TestDetailTeacher, get_td_old.TestDetailActive, get_td_old.TestDetailNote);
        }
        %>
</body>
</html>
